<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
//列表控制器
class ListController extends Controller{
	//列表页
	public function index(){
		//标签名处理
		$tid=Q('get.tid',0,'intval');
		if($tid){
			$tagModel= new \Common\Model\Tag;
			$name=$tagModel->where("tid={$tid}")->pluck('tname');
			//统计文章总数
			$arcTagModel=new \Common\Model\Arctag;
			$total=$arcTagModel->where("tag_tid=$tid")->count();
			//根据tid筛选出来的文章
			$arcData=$arcTagModel->join('article','article_aid','=','aid')->join('category','category_cid','=','cid')->where("tag_tid={$tid} AND is_recycle=0")->get();	
		}
		//分类
		$cid=Q('get.cid',0,'intval');
		if($cid){
			$cateModel=new \Common\Model\Cate;
			$name=$cateModel->where("cid={$cid}")->pluck('cname');
			//统计分类的文章总数（包括子分类）
			$cids=$cateModel->getSon($cateModel->get(),$cid);
			$cids[]=$cid;
			$arcModel=new \Common\Model\Arc;
			$total=$arcModel->where("category_cid in(".implode(',',$cids).")")->count();
			$arcData=$arcModel->join('category','category_cid','=','cid')->where("category_cid in(".implode(',',$cids).") and is_recycle=0")->get();						
		}
		//名称
		View::with('name',$name);
		//总共多少篇文章
		View::with('total',$total);
		//给文章数据压入标签
		$arcTagModel=new \Common\Model\ArcTag;
		foreach($arcData as $k=>$v){
			$arcData[$k]['tag']=$arcTagModel->join('tag','tag_tid','=','tid')->where("article_aid={$v['aid']}")->field('tid,tname')->get();
		}
		//分配文章数据
		View::with('arcData',$arcData);
		
		View::make();
	}
}





























 ?>